package com.shxzz.easy12306.services.pay.dto.convert;

import com.shxzz.easy12306.services.pay.common.enums.PayChannelEnum;
import com.shxzz.easy12306.services.pay.dao.entity.PayDO;
import com.shxzz.easy12306.services.pay.dto.ali.AliRefundRequest;
import com.shxzz.easy12306.services.pay.dto.base.RefundRequest;
import com.shxzz.easy12306.framework.starter.common.dto.pay.RefundReqDTO;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.util.Objects;

/**
 * 退款请求转换工具类
 * @author shxzz
 * @create 2024-03-17-22:27
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class RefundCommandConvert {

    public static RefundRequest convert(PayDO payDO, RefundReqDTO refundReqDTO) {
        RefundRequest refundRequest = null;
        if (Objects.equals(payDO.getChannel(), PayChannelEnum.ALI_PAY.getCode())) {
            AliRefundRequest aliRefundRequest = new AliRefundRequest();
            aliRefundRequest.setOrderSn(payDO.getOrderSn());
            aliRefundRequest.setTradeNo(payDO.getTradeNo());
            aliRefundRequest.setRefundAmount(new BigDecimal(refundReqDTO.getRefundAmount()));
            aliRefundRequest.setChannel(payDO.getChannel());
            aliRefundRequest.setTradeType(payDO.getTradeType());
            refundRequest = aliRefundRequest;
        }
        return refundRequest;
    }

}
